package com.ruoyi.ma.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.base.domain.bo.BaseBsBdBo;
import com.ruoyi.base.domain.vo.BdTreeVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ma.domain.vo.MaMaterialSupplierVo;
import com.ruoyi.ma.domain.bo.MaMaterialSupplierBo;
import com.ruoyi.ma.service.IMaMaterialSupplierService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料供应商信息
 *
 * @author tll
 * @date 2024-11-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ma/materialSupplier")
public class MaMaterialSupplierController extends BaseController {

    private final IMaMaterialSupplierService iMaMaterialSupplierService;

    /**
     * 查询材料供应商信息列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<MaMaterialSupplierVo> list(MaMaterialSupplierBo bo, PageQuery pageQuery) {
        return iMaMaterialSupplierService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出材料供应商信息列表
     */
    @SaCheckLogin
    @Log(title = "材料供应商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MaMaterialSupplierBo bo, HttpServletResponse response) {
        List<MaMaterialSupplierVo> list = iMaMaterialSupplierService.queryList(bo);
        ExcelUtil.exportExcel(list, "材料供应商信息", MaMaterialSupplierVo.class, response);
    }

    /**
     * 获取材料供应商信息详细信息
     *
     * @param supplierId 主键
     */
    @SaCheckLogin
    @GetMapping("/{supplierId}")
    public R<MaMaterialSupplierVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long supplierId) {
        return R.ok(iMaMaterialSupplierService.queryById(supplierId));
    }

    /**
     * 新增材料供应商信息
     */
    @SaCheckLogin
    @Log(title = "材料供应商信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MaMaterialSupplierBo bo) {
        return toAjax(iMaMaterialSupplierService.insertByBo(bo));
    }

    /**
     * 修改材料供应商信息
     */
    @SaCheckLogin
    @Log(title = "材料供应商信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MaMaterialSupplierBo bo) {
        return toAjax(iMaMaterialSupplierService.updateByBo(bo));
    }

    /**
     * 删除材料供应商信息
     *
     * @param supplierIds 主键串
     */
    @SaCheckLogin
    @Log(title = "材料供应商信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] supplierIds) {
        return toAjax(iMaMaterialSupplierService.deleteWithValidByIds(Arrays.asList(supplierIds), true));
    }

}
